<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :footer="null"
    switchFullscreen
    @cancel="handleCancel"
    cancelText="关闭">
    <div>
      <a-table
        size="small"
        bordered
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ y: 240 }"
        @change="handleTableChange">

      </a-table>
    </div>
  </j-modal>

</template>

<script>

  import {filterObj} from '@/utils/util'
  import {getAction, postAction} from '@/api/manage'
  import $ from 'jquery'

  export default {
    name: "materialStockModal",
    data() {
      return {
        currentSupplierId: 0,
        currentMaterialId: 0,
        width: '90%',
        model: {},
        title: "",
        visible: false,
        placement: 'right',
        description: '',
        // 查询条件
        queryParam: {},
        //职务条件
        post: '',
        // 表头
        columns: [
          {
            title: '名称',
            align: "center",
            dataIndex: 'material.materialName',
          },
          {
            title: '型号',
            align: "center",
            dataIndex: 'material.modelNumber'
          },
          {
            title: '规格',
            align: "center",
            dataIndex: 'material.specifications'
          },
          {
            title: '品牌',
            align: "center",
            dataIndex: 'material.brand'
          },
          {
            title: '市场价',
            align: "center",
            dataIndex: 'material.marketPrice'
          },
          {
            title: '预算价',
            align: "center",
            dataIndex: 'material.estimatedCost'
          },
          {
            title: '仓库',
            align: "center",
            dataIndex: 'depository.depositoryName'
          },
          {
            title: '库存',
            align: "center",
            dataIndex: 'stock'
          },

        ],
        //数据集
        dataSource: [],
        // 分页参数
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        loading: false,
        selectedRowKeys: [],
        selectedRows: [],
        url: {
          queryMaterialStockByMaterialName: "/ghSupplychainDepositoryItem/queryMaterialStockByMaterialName"
        },
        value:0
      }
    },
    created() {

    },
    methods: {
      showMaterialStock(record){
        this.visible = true;
        this.currentMaterialId = record.materialId;
        this.loadData();
      },
      searchQuery() {
        this.loadData(1);
      },
      searchReset() {
        this.queryParam = {};
        this.loadData(1);
      },
      handleCancel() {
        this.close();
      },

      loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        let params = this.getQueryParams();//查询条件
        if (this.currentMaterialId != null){
          params.materialId = this.currentMaterialId;
        }
        getAction(this.url.queryMaterialStockByMaterialName, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records||res.result;
          }
        })
      },
      getQueryParams() {
        var param = Object.assign({}, this.queryParam, this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.post = this.post;
        return filterObj(param);
      },
      getQueryField() {
        //TODO 字段权限控制
      },
      onSelectAll(selected, selectedRows, changeRows) {
        /*console.log("**************" + selected, selectedRows, changeRows);*/
      },
      onSelect(record, selected, selectedRows) {
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectedRows = [];
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectionRows
      },

      handleTableChange(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        this.ipagination = pagination;
        this.loadData();
      },
      close() {
        this.dataSource = [];
        this.$emit('close');
        this.visible = false;
        this.onClearSelected();
        this.queryParam = {};
        $(".clearValue").value = "";
      },
      submitCallback() {
        this.$emit('ok');
        this.visible = false;
      },
    }
  }
</script>

<style scoped lang="less">

  .ant-card-body .table-operator {
    margin-bottom: 18px;
  }

  .ant-table-tbody .ant-table-row td {
    padding-top: 15px;
    padding-bottom: 15px;
  }

  .anty-row-operator button {
    margin: 0 5px
  }

  .ant-btn-danger {
    background-color: #ffffff
  }

  .ant-modal-cust-warp {
    height: 100%
  }

  .ant-modal-cust-warp .ant-modal-body {
    height: calc(100% - 110px) !important;
    overflow-y: auto
  }

  .ant-modal-cust-warp .ant-modal-content {
    height: 90% !important;
    overflow-y: hidden
  }
</style>